from django.contrib import admin
from .models import Post, Category, Comment

# Register your models here.

class PostAdmin(admin.ModelAdmin):
	#帖子列页面中展示的字段
    list_display = ('title', 'author', 'created', 'view_count', 'comment_count', 'status')
    #右侧边栏允许你根据list_filter属性中指定的字段来过滤返回结果
    list_filter = ('status', 'created', 'updated', 'author')
    #通过使用search_fields属性定义一个搜索字段列
    search_fields = ('title', 'author__username')
    raw_id_fields = ('author',)
    #通过时间层快速导航的栏，该栏通过定义date_hierarchy属性实现
    date_hierarchy = 'created'
    #帖子默认的通过Status和Created列进行排序。这是因为你通过使用ordering属性指定了默认排序
    ordering = ['status', '-created']


class CategoryAdmin(admin.ModelAdmin):
	list_display = ('name',)
		

class CommentAdmin(admin.ModelAdmin):
    list_display = ('username', 'email', 'post', 'created', 'active')
    list_filter = ('active', 'created', 'updated')
    search_fields = ('username', 'email', 'content')

admin.site.register(Post, PostAdmin)
admin.site.register(Comment, CommentAdmin)
admin.site.register(Category, CategoryAdmin)